﻿using FastGPT_Admin.Service;
using FastGPT_Admin.Setting;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FastGPT_Admin.Controller
{
    internal class TeamsController
    {
        private string connectionString = AppSettings.GlobalSettingsInstance.ConnectionString;
        private string databaseName = "fastgpt";
        private string collectionName = "teams";
        private TeamsService _teamsService;

        public TeamsController() 
        {
            _teamsService = new TeamsService(connectionString, databaseName, collectionName);
        }

        public string CheckTeamsName(string Name)
        {
            List<Teams> teams = _teamsService.Read(Name, false);
            if (teams == null || teams.Count != 1)
            {
                return "Null";
            } else
            {
                return teams[0].Id.ToString();
            }
        }

        public ObjectId CreateTeams(Teams model)
        {
            try
            {
                ObjectId teamsId = _teamsService.Create(model);
                return teamsId;
            }
            catch (Exception ex)
            {
                return ObjectId.Empty;
            }
        }
    }
}
